﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;

namespace GPI.Action
{
    public class URLAction
    {
        public static string GetNavigationByNode(string id, string space)
        {
            GPI.Server.NodeService server = new GPI.Server.NodeService();
            string ul = "<a href='ShowPage.aspx?id={0}'>{1}</a>";
            StringBuilder ulTmp=new StringBuilder();
            NodeInfo model= server.GetModel(id.ToInt(0));
            List<string> url = new List<string>();
            url.Add(String.Format(ul , model.Id, model.NodeName));
            while (model.ParentID != 0)
            {
                NodeInfo tmp = server.GetModel(model.ParentID.Value);
                url.Add(String.Format(ul + space, tmp.Id, tmp.NodeName));
                model = tmp; 
            }
            for (int i = url.Count-1; i >=0; i--)
            {
                ulTmp.Append(url[i]);
            }
            return ulTmp.ToString();
        }

        public static string GetNavigationByNew(string id, string space)
        {
            GPI.Server.NewListService serverNew = new GPI.Server.NewListService();
            string New = "<a href='New.aspx?id={0}'>{1}</a>";
            StringBuilder ulTmp = new StringBuilder();
            NewListInfo model = serverNew.GetModel(id.ToInt(0));
            string node = GetNavigationByNode(model.NodeID.Value.ToString(), space);
            ulTmp.AppendFormat(node + space);
            ulTmp.AppendFormat(New, model.ID, model.NewTitle);
            return ulTmp.ToString();
        }
    }
}
